/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#include "xevent.h"

BEG_NS_SMART

event_t::event_t() : m_bSet(false)
{
    X_EVENT_SigConstruct(m_evt);
}

event_t::~event_t()
{
    X_EVENT_SigDestruct(m_evt);
}

int event_t::reset()
{
    X_EVENT_SigReset(m_evt);
    m_bSet = false;
    return 0;
}

int event_t::setEventInLock()
{
    m_bSet = true;
    X_EVENT_SigSet(m_evt);
    return 0;
}

int event_t::timedWaitInLock(int timeout_ms)
{
    int result = 0;
    if(!m_bSet) {
        X_EVENT_SigWait(m_evt, m_mutex, timeout_ms, result);
    }
    reset();
    return result; //0,success; -1,failed
}


END_NS_SMART
